Property Grid Object Model
The main class you will work with is the PropertyGrid class. This represents the control itself. However, you will also need to understand editors, and for dynamic population of the grid you will need to understand nodes.
About Editors
An editor is an object that provides a value editing service for the property grid. Editors are responsible for populating the right-hand column of the grid, where the user can view and edit values. The property grid provides a number of built-in editors, which allow users to edit strings, numeric values, dates and enumerated types. You will need to know about editors if you want to:
- Select a non-default built-in editor (for example, use the built-in slider editor, rather than the normal text editor, to edit a numeric value).
- Customize the appearance of a built-in editor (for example, style the built-in check box editor to reflect your application’s visual theme).
- Provide a custom editor that gives users a tailored interface for editing a particular property or type of property (for example, a color chooser).
The types of editor you will normally work with are type editors and property editors.
- A type editor defines a user interface for editing a particular type of object, wherever it appears in the property grid. For example, a custom phone number editor would typically be used whenever an object of type PhoneNumber appears.
- A property editor defines a user interface for editing a particular property, identified by a declaring type and a property name. For example, an editor that allows users to select a numeric value by resizing a picture of a hat would typically be used only for the HatSize property of the Person type, not for other numeric properties like Height or Age.
Although an editor normally allows users to modify the value, it is not required to do so. In fact, an editor works by providing a data template, which the property grid uses to render the property value. For an editor to allow users to modify the value simply means that the template allows user input and uses two-way binding to propagate changes back to the source; conversely, you can use the editor model to display values as read-only by creating a data template which does not allow user input.
About Nodes
A node is an entry in the property grid. When the grid automatically populates because the SelectedObject or ItemsSource property has been set, you do not need to work with nodes. However, if you manage the contents of the grid directly from code using the AddNode and RemoveNode methods, you may need to know something about nodes.
When you add an item to the grid using AddNode, the grid returns the resulting Node object to you. You can use this object for two things:
- You can query the node’s Value property. This enables you to retrieve the result of any changes made by the user.
- You can pass the node to the RemoveNode method to remove it from the grid.
You don’t need to create Node objects yourself.